﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AbstraX.ServerInterfaces;
using AbstraX.Bindings;
using CodeGenerationPipeline;
using PresentationServices.Templates;
using System.IO;
using CodeGenerationPipeline.Contracts;
using WSDLGenerator;

namespace PresentationServices
{
    public class PresentationServicesGenerator : BaseGenerator
    {
        public override event WatchProcess OnWatchProcess;

        public override string Name
        {
            get 
            {
                return "Presentation Services Generator";
            }
        }

        public override string Description
        {
            get
            {
                return "";
            }
        }

        public override ICodeGenerationPackage GenerateFrom(Dictionary<string, IElementBuild> builds, DirectoryInfo workspaceDirectory)
        {
            this.workspaceDirectory = workspaceDirectory.FullName;

            return PackageGenerator.GeneratePackage(builds)
                .ApplyPortType(typeof(IServiceProvider))
                    .AddGenericArgument(typeof(IServiceProvider))
                    .AddParameter(t1 => "Hello")
                .Support()
                    .MapAllOperations((Type t2, IElement element, OptionalDataContextOperation odco) => t2.GetMethods().Where(m => m.Name == odco.GetName()).Single())
                        .When(() => OptionalDataContextOperation.Delete)
                            .Create(typeof(IServiceProvider))
                .Requirements()
                    .AddIncludeFile("", "", BuildAction.BuildActionCompile, "", "")
                .BuildPackage();
        }

        public override ICodeGenerationPackage GenerateFromPackage(ICodeGenerationPackage incomingPackage)
        {
            this.workspaceDirectory = incomingPackage.WorkspaceDirectory.FullName;

            return null;
        }

        public override void OnError(int errorCode, Exception exception, string error)
        {
        }

        public override void OnProcessExited(int exitCode)
        {
        }

        public override void OnProcessTimeout()
        {
        }
    }
}
